package com.itheima.service.impl;

import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service(interfaceClass=ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    //本地注入
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private MemberDao memberDao;

    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        //建立一个map集合用来封装对象
         Map<String,Object>date=new HashMap<>();


        //今日时间
        String time = DateUtils.parseDate2String(new Date());
        //最近一周时间
        String monday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //最近一个月时间
        String month = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

        //今日时间封装
        date.put("reportDate",time);

        //获取当日会员数量
        Integer todayNewMember = memberDao.findMemberCountByDate(time);
        date.put("todayNewMember",todayNewMember);
        //获取会员总数
        Integer totalMember = memberDao.findMemberTotalCount();
        date.put("totalMember",totalMember);
        //获取一周的会员数量
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(monday);
        date.put("thisWeekNewMember",thisWeekNewMember);
        //获取一个月会员数量
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(month);
        date.put("thisMonthNewMember",thisMonthNewMember);


        //今天已预约数量
        Integer todayOrderNumber = orderDao.findOrderCountByDate(time);
        date.put("todayOrderNumber",todayOrderNumber);
        //今天到诊数量
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(time);
        date.put("todayVisitsNumber",todayVisitsNumber);

        //一周的预约数量
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(monday);
        date.put("thisWeekOrderNumber",thisWeekOrderNumber);
        //一周的到诊数量
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountByDate(monday);
        date.put("thisWeekVisitsNumber",thisWeekVisitsNumber);


        //一个月的预约数量
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(month);
        date.put("thisMonthOrderNumber",thisMonthOrderNumber);
        //一个月的到诊数量
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountByDate(month);
        date.put("thisMonthVisitsNumber",thisMonthVisitsNumber);


        //热门套餐
        List<Map> hotSetmeal = orderDao.findHotSetmeal();

        date.put("hotSetmeal",hotSetmeal);

        return date;
    }
}
